#include <iostream>
#include <string>
#include <stack>

using namespace std;

class Solution
{
public:
    int calculate(string s)
    {
        auto eval = [](int n1, int n2, char op)
        {
            if (op == '+')
                return n1 + n2;
            else
                return n1 - n2;
        };
        stack<pair<int, char>> ops;
        ops.push({0, '+'});
        int number = 0;
        for (const char c : s)
        {
            int n = 0;
            switch (c)
            {
            case '+':
            case '-':
                n = eval(ops.top().first, number, ops.top().second);
                ops.pop();
                ops.push({n, c});
                number = 0;
                break;
            case '(':
                ops.push({0, '+'});
                number = 0;
                break;
            case ')':
                n = eval(ops.top().first, number, ops.top().second);
                ops.pop();
                number = n;
                break;
            case ' ':
                break;
            default:
                number = number * 10 + c - '0';
            }
        }
        return eval(ops.top().first, number, ops.top().second);
    }
};

int main()
{
    cout << "Code224" << endl;
    Solution s;
    string str = "2147483647";
    cout << s.calculate(str);
    return 0;
}